﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;
/// <summary>
///Login 的摘要说明
/// </summary>
public class User:Page
{
    private MysqlHelp AsUserLog;
    private string conn;
	public User()
	{
        AsUserLog = new MysqlHelp();
	}
    /// <summary>
    /// 检查用户名是否存在
    /// </summary>
    /// <param name="UserName">
    /// 用户名
    /// </param>
    /// <returns></returns>
   bool CheckUserName(string UserName)
    {
        UserName = UserName.Trim();
        conn = "select * from user where username='" + UserName + "'";
        DataTable UserBack = AsUserLog.GetDatabysql(conn);
        if (UserBack.Rows.Count != 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    /// <summary>
    /// 登陆检测
    /// </summary>
    /// <param name="AsUserName">用户名</param>
    /// <param name="AsPassWord">密码</param>
    /// <returns></returns>
    string UerLogin(string AsUserName,string AsPassWord)
    {
        AsUserName = AsUserName.Trim();
        AsPassWord = AsPassWord.Trim();
        if(!CheckUserName(AsUserName))
        {
            return "无此用户";
        }
        conn = "select * from user where username='" + AsUserName + "'and password='" + AsPassWord + ",";
        DataTable UserBack = AsUserLog.GetDatabysql(conn);
        if(UserBack.Rows.Count!=0)
        {
            return "登陆成功";
        }
        else
        {
            return "密码错误";
        }
    }
    /// <summary>
    /// 登陆状态检测
    /// </summary>
    /// <returns></returns>
    string CheckIsLoged()
    {
        if (Session["AsUserName"] != null && Session["AsUserName"].ToString() != "")
        {
            return Session["AsUserName"].ToString();
        }
        else
        {
            return null;
        }
    }
}
